import { useRouter } from 'vue-router'
import { useStore } from '/@/store'
import { useLoginer } from '/@/use/loginer'
import { getUserInfo } from '../../util/business-util'

export function useLoginAfter() {
  const router = useRouter()

  const { isEducation, isSchool } = useLoginer()

  const { dispatch, state, commit } = useStore()

  let userInfo = {
    postName: '',
    roleName: '',
  }

  return {
    async loginRedirect() {
      userInfo = await getUserInfo(commit, state, state.user.userId, false)

      if (userInfo.postCategory == '4') {
        router.push({
          name: 'student-evaluate',
        })
        return
      }

      if (userInfo.roleName == '学生' || userInfo.roleName == '员工') {
        router.push({
          name: 'student-evaluate',
        })
        return
      }

      await dispatch('getTenant')
      if (isEducation.value) {
        router.push({
          name: 'BoardEducationBureau',
        })
        return
      }

      if (isSchool.value) {
        router.push({
          name: 'BoardSchool',
        })
        return
      }

      router.push({
        name: 'Home',
      })
    },
  }
}
